home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / private / _makenew.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  3KB  |  148 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define    CURSES_LIBRARY    1
  5. #include <curses.h>
  6.  
  7. #ifdef PDCDEBUG
  8. char *rcsid__makenew = "$Header: C:\CURSES\private\RCS\_makenew.c 2.1 1993/06/18 20:23:01 MH Rel MH $";
  9. #endif
  10.  
  11.  
  12.  
  13.  
  14. /*man-start*********************************************************************
  15.  
  16.   PDC_makenew()    - Create a WINDOW* (sans line allocation)
  17.  
  18.   PDCurses Description:
  19.      This is a private PDCurses routine.
  20.  
  21.      Allocates all data for a new WINDOW* except the actual lines
  22.      themselves.
  23.  
  24.   PDCurses Return Value:
  25.      This function returns a valid WINDOW* on success and NULL on error.
  26.  
  27.   PDCurses Errors:
  28.      If PDC_makenew() is unable to allocate memory for the window
  29.      structure, it will free all allocated memory and return
  30.      a NULL pointer.
  31.  
  32.   Portability:
  33.      PDCurses    WINDOW* PDC_makenew( int num_lines, int num_columns,
  34.                       int begy, int begx );
  35.  
  36. **man-end**********************************************************************/
  37.  
  38. WINDOW*    PDC_makenew(int num_lines, int num_columns, int begy, int begx)
  39. {
  40. extern    void*    (*mallc)( size_t );
  41. extern    void*    (*callc)( size_t, size_t );
  42. extern    void    (*fre)( void* );
  43.  
  44.     short    i;
  45.     WINDOW *win;
  46.  
  47. #ifdef PDCDEBUG
  48.     if (trace_on) PDC_debug("PDC_makenew() - called: lines %d cols %d begy %d begx %d\n",num_lines,num_columns,begy,begx);
  49. #endif
  50.  
  51.     /*
  52.     *    Use the standard runtime malloc/calloc package or use
  53.     *    the user's emalloc/ecalloc package.
  54.     *
  55.     *    Allocate the window structure itself
  56.     */
  57.     if ((win = (*mallc)(sizeof(WINDOW))) == (WINDOW *)NULL)
  58.     {
  59.         return( win );
  60.     }
  61.  
  62.     /*
  63.     * allocate the line pointer array
  64.     */
  65.     if ((win->_y = (*callc)(num_lines, sizeof(chtype *))) == NULL)
  66.     {
  67.         (*fre)(win);
  68.         return( (WINDOW *)NULL );
  69.     }
  70.  
  71.     /*
  72.     * allocate the minchng and maxchng arrays
  73.     */
  74.     if ((win->_firstch = (*callc)(num_lines, sizeof(int))) == NULL)
  75.     {
  76.         (*fre)(win->_y);
  77.         (*fre)(win);
  78.         return( (WINDOW *)NULL );
  79.     }
  80.     if ((win->_lastch = (*callc)(num_lines, sizeof(int))) == NULL)
  81.     {
  82.         (*fre)(win->_firstch);
  83.         (*fre)(win->_y);
  84.         (*fre)(win);
  85.         return( (WINDOW *)NULL );
  86.     }
  87.  
  88.     /*
  89.     * initialize window variables
  90.     */
  91.     win->_curx = 0;
  92.     win->_cury = 0;
  93.     win->_maxy = num_lines;        /* real max screen size */
  94.     win->_maxx = num_columns;    /* real max screen size */
  95.     win->_pmaxy = num_lines;    /* real max window size */
  96.     win->_pmaxx = num_columns;    /* real max window size */
  97.     win->_begy = begy;
  98.     win->_begx = begx;
  99.     win->_flags = 0;
  100.     win->_attrs = 0;        /* No attributes */
  101.     win->_tabsize = 8;
  102.     win->_clear = (bool) ((num_lines == LINES) && (num_columns == COLS));
  103.     win->_leave = FALSE;
  104.     win->_scroll = FALSE;
  105.     win->_nodelay = FALSE;
  106.     win->_use_keypad = FALSE;
  107.     win->_use_idl = FALSE;
  108.     win->_tmarg = 0;
  109.     win->_bmarg = num_lines - 1;
  110.     win->_title = NULL;
  111.     win->_title_ofs = 1;
  112.     win->_title_attr = win->_attrs;
  113.     win->_blank = ' ';
  114.     win->_parent = NULL;
  115.  
  116.     memset(win->_borderchars, '\0', 8*sizeof(chtype));
  117.  
  118.     /*
  119.     * init to say window unchanged
  120.     */
  121.     for (i = 0; i < num_lines; i++)
  122.     {
  123.         win->_firstch[i] = 0;
  124.         win->_lastch[i] = num_columns - 1;
  125.     }
  126.  
  127.     /*
  128.     * set flags for window properties
  129.     */
  130.     if ((begy + num_lines) == LINES)
  131.     {
  132.         win->_flags |= _ENDLINE;
  133.         if ((begx == 0) &&
  134.             (num_columns == COLS) &&
  135.             (begy == 0))
  136.         {
  137.             win->_flags |= _FULLWIN;
  138.         }
  139.     }
  140.  
  141.     if (((begy + num_lines) == LINES) &&
  142.         ((begx + num_columns) == COLS))
  143.     {
  144.         win->_flags |= _SCROLLWIN;
  145.     }
  146.     return( win );
  147. }
  148.